local skel = fk.CreateSkill {
  name = "emo__fuzuo",
}

skel:addEffect(fk.GameStart, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askToChoosePlayers(player, {
      targets = player.room.alive_players,
      min_num = 1, max_num = 1, skill_name = skel.name, cancelable = false,
      prompt = "#emo__fuzuo-choose",
    })
    event:setCostData(self, { tos = tos })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:addPlayerMark(to, "@@emo__shachou", 1)
    room:setPlayerMark(player, skel.name, to.id)
    local skills = {"yingzi", "guzheng"}
    room:handleAddLoseSkills(to, skills)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      local to = player.room:getPlayerById(player:getMark(skel.name))
      if to and to ~= player and to:isAlive() and not to:isKongcheng() then
        local n = 0
        for _, move in ipairs(data) do
          if move.to == to and move.toArea == Card.PlayerHand then
            n = n + #move.moveInfo
          end
        end
        if n > 1 then
          event:setCostData(self, { tos = { to } })
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local cards = room:askToCards(to, {
      min_num = 1, max_num = 1, cancelable = true, include_equip = false, skill_name = skel.name,
      prompt = "#emo__fuzuo-give:"..player.id ,
    })
    if #cards > 0 then
      event:setCostData(self, {tos = { to }, cards = cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local cards = event:getCostData(self).cards
    room:obtainCard(player, cards, false, fk.ReasonGive, to, skel.name)
  end,
})

Fk:loadTranslationTable{
  ["emo__fuzuo"] = "辅佐",
  [":emo__fuzuo"] = "游戏开始时，你选择一名角色，令其获得“社长”标记，其视为拥有“英姿”和“固政”。当其一次性获得至少两张牌后，可以交给你一张手牌。",

  ["#emo__fuzuo-choose"] = "辅佐：将一名角色标记为“社长”，其获得“英姿”和“固政”",
  ["#emo__fuzuo-give"] = "辅佐：你可以交给 %src 一张手牌",
  ["@@emo__shachou"] = "社長",
}

return skel
